/**
 * 
 */

NavigationPortlet = Class.extend({
	init:function() {
		this.name = "NavigationPortlet";
		this.viewId = "NavigationPortlet-NavigationPortlet";
		this.pageName = "";
		this.pageHeader = "";
		this.pageClass = "";
	},

	buildTemplate: function(){
		var data = this.getPageData();
		var pages = data.pages;
		var dataChildren = Array();
		for(var key in pages){
			var obj = {};
			obj.pageHeader = pages[key].pageHeader;
			obj.pageClass = pages[key].pageClass;
			obj.pageName = pages[key].pageContent;
			dataChildren.push(tmpl(this.name + "-Item", obj));
		}
		
		var objParam = {};
		objParam.children = dataChildren;
		return tmpl(this.name + "-List",objParam);
	},
	
	getPageData: function(){
		var pageName = SingletonFactory.getInstance(Page).getRequest().getName();
		var data = null;
		if(this.requestForResource("Config" + pageName) == undefined){
			data = tmpl(this.name + "-Config",{}); 
		} else {
			data = tmpl(this.name + "-Config" + pageName,{});
		}
		return eval('('+data+')');
	},
	
	render: function(){
		//console.log($(this.buildTemplate()));
		return $(this.buildTemplate()).children();
	},
	
	run: function() {
		this.getPortletPlaceholder().drawToCanvas(this.render());
		$("#"+this.placeholder.canvas.id).css("float","left");
		$("#"+this.placeholder.canvas.id).css("margin-left","-150px");
		$("#"+this.placeholder.canvas.id).css("margin-top","50px");
		$("#"+this.placeholder.canvas.id).css("background-color","#f5f3f4");
		$("#"+this.placeholder.canvas.id).css("-moz-border-radius","10px 10px 10px 10px");
		$("#"+this.placeholder.canvas.id).css("-webkit-border-radius","10px 10px 10px 10px");
		$("#"+this.placeholder.canvas.id).css("border-radius","10px 10px 10px 10px");
		$("#"+this.placeholder.canvas.id).css("min-width","150px");
	}
}).implement(RenderInterface).implement(PortletInterface);